added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / ATLCOMClient / ReadMe.txt
blob7c208d3f816f1a6d5ec0f4cf8f1b1dcfd9df9823
1 ========================================================================
2     CONSOLE APPLICATION : ATLCOMClient Project Overview
3 ========================================================================
5 /////////////////////////////////////////////////////////////////////////////
6 Use:
8 ATLCOMClient shows you how to call COM server objects in ATL and implement an 
9 event sink using the ATL IDispEventImpl and IDispEventSimpleImpl classes for 
10 events in the COM server.
12 For the event sink, you can use IDispEventImpl when you have access to a type 
13 library. Use IDispEventSimpleImpl when you do not have access to the type 
14 library or when you want to be more efficient by not loading the type library.
17 /////////////////////////////////////////////////////////////////////////////
18 Project Relation:
20 ATLCOMClient -> ATLDllCOMServer
21 ATLCOMClient is the client application of the COM server ATLDllCOMServer.
24 /////////////////////////////////////////////////////////////////////////////
25 Creation:
27 Step1. Create a C++ Win32 console project in Visual Studio 2008, and add 
28 common header files for ATL.
30 #include <atlbase.h>
31 #include <atlstr.h>
32 #include <atlcom.h> // This header file requires to be added manually
34 Step2. Declare and initialize the current ATL module.
36         // You may derive a class from CAtlModule and use it if you want to 
37         // override something.
38         class CATLCOMClientModule : public CAtlExeModuleT<CATLCOMClientModule>
39         { };
41         // Declare and initialize the current ATL module. 
42         CATLCOMClientModule _AtlModule;
44 Step3. Import the type library of the COM server:
46         #import "ATLDllCOMServer.dll" no_namespace named_guids
47         // [-or-]
48         //#import "libid:9B23EFED-A0C1-46B6-A903-218206447F3E" no_namespace named_guids
50 Step4. Add the file ATLSimpleSinkObject.h. The file contains three different 
51 sink objects all of which handle the FloatPropertyChanging event which is 
52 fired by the source COM object "ATLDllCOMServer.SimpleObject". 
54 Step5. Create the ATLDllCOMServer.SimpleObject COM object using the 
55 #import directive and smart pointers.
57         CComQIPtr<ISimpleObject> spSimpleObj;
58         hr = spSimpleObj.CoCreateInstance(OLESTR(
59                 "ATLDllCOMServer.SimpleObject"));
61 Step6. Use sink object 1 (CATLSimpleSinkObject1) to set up the sink for the 
62 events of the source COM object.
64         6.1 Construct the sink object CATLSimpleSinkObject1 defined in 
65         ATLSimpleSinkObject.h
66         
67         6.2 Make sure the COM object corresponding to pUnk implements 
68         IProvideClassInfo2 or IPersist*. Call this method to extract info about
69         source type library if you specified only 2 parameters to IDispEventImpl.
71         6.3 Connect the sink and source, spSimpleObj is the source COM object
72         
73         6.4 Invoke the source COM object
74         
75         6.5 Disconnect from the source COM object if connected
76         
77         6.6 Destroy the sink object
79 Step7. Use sink object 2 (CATLSimpleSinkObject2) to set up the sink for the 
80 events of the source COM object.
82         7.1 Construct the sink object CATLSimpleSinkObject2 defined in 
83         ATLSimpleSinkObject.h
84         
85         7.2 Connect the sink and source, m_spSrcObj is the source COM object
86         
87         7.3 Invoke the source COM object
88         
89         7.4 Disconnect from source if connected
90         
91         7.5 Destroy the sink object
93 Step8. Use sink object 3 (CATLSimpleSinkObject3) to set up the sink for the 
94 events of the source COM object.
96         8.1 Construct the sink object CATLSimpleSinkObject3 defined in 
97         ATLSimpleSinkObject.h
98         
99         8.2 Connect the sink and source, m_spSrcObj is the source COM object
100         
101         8.3 Invoke the source COM object
102         
103         8.4 Disconnect from source if connected
104         
105         8.5 Destroy the sink object
107 Step9. Release the COM object.
110 /////////////////////////////////////////////////////////////////////////////
111 References:
113 KB: AtlEvnt.exe sample shows how to creates ATL sinks by using the ATL 
114 IDispEventImpl and IDispEventSimpleImpl classes
115 http://support.microsoft.com/kb/194179
118 /////////////////////////////////////////////////////////////////////////////